<?php
class SemesterApartementsController extends AppController {

	var $name = 'SemesterApartements';
	var $helpers = array('Html', 'Form' );
	var $uses = array('SemesterApartement', 'Semester', 'Language', 'Apartement');

	function index() {
		$this->SemesterApartement->recursive = 2;
		$this->set('semesterApartements', $this->SemesterApartement->findAll());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash('Invalid id for Semester Apartement.');
			$this->redirect('/semester_apartements/index');
		}
		$this->set('semesterApartement', $this->SemesterApartement->read(null, $id));
	}

	function add() {
		$this->set('semesterList', $this->Semester->getSemesterList());
		$this->set('apartementList', $this->Apartement->getApartementList());
		$this->set('languageList', $this->Language->getLanguageList());
		$this->set('genderList', array('Male' => 'Male', 'Female' => 'Female'));
		if (empty($this->data)) {
			$this->render();
		} else {
			$this->cleanUpFields();
			if ($this->SemesterApartement->save($this->data)) {
				$this->Session->setFlash('The Semester Apartement has been saved');
				$this->redirect('/semester_apartements/index');
			} else {
				$this->Session->setFlash('Please correct errors below.');
			}
		}
	}

	function edit($id = null) {
		if (empty($this->data)) {
			if (!$id) {
				$this->Session->setFlash('Invalid id for Semester Apartement');
				$this->redirect('/semester_apartements/index');
			}
			$this->data = $this->SemesterApartement->read(null, $id);
		} else {
			$this->cleanUpFields();
			if ($this->SemesterApartement->save($this->data)) {
				$this->Session->setFlash('The SemesterApartement has been saved');
				$this->redirect('/semester_apartements/index');
			} else {
				$this->Session->setFlash('Please correct errors below.');
			}
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash('Invalid id for Semester Apartement');
			$this->redirect('/semester_apartements/index');
		}
		if ($this->SemesterApartement->del($id)) {
			$this->Session->setFlash('The Semester Apartement deleted: id '.$id.'');
			$this->redirect('/semester_apartements/index');
		}
	}


	function admin_index() {
		$this->SemesterApartement->recursive = 0;
		$this->set('semesterApartements', $this->SemesterApartement->findAll());
	}

	function admin_view($id = null) {
		if (!$id) {
			$this->Session->setFlash('Invalid id for Semester Apartement.');
			$this->redirect('/admin/semester_apartements/index');
		}
		$this->set('semesterApartement', $this->SemesterApartement->read(null, $id));
	}

	function admin_add() {
		if (empty($this->data)) {
			$this->render();
		} else {
			$this->cleanUpFields();
			if ($this->SemesterApartement->save($this->data)) {
				$this->Session->setFlash('The Semester Apartement has been saved');
				$this->redirect('/admin/semester_apartements/index');
			} else {
				$this->Session->setFlash('Please correct errors below.');
			}
		}
	}

	function admin_edit($id = null) {
		if (empty($this->data)) {
			if (!$id) {
				$this->Session->setFlash('Invalid id for Semester Apartement');
				$this->redirect('/admin/semester_apartements/index');
			}
			$this->data = $this->SemesterApartement->read(null, $id);
		} else {
			$this->cleanUpFields();
			if ($this->SemesterApartement->save($this->data)) {
				$this->Session->setFlash('The SemesterApartement has been saved');
				$this->redirect('/admin/semester_apartements/index');
			} else {
				$this->Session->setFlash('Please correct errors below.');
			}
		}
	}

	function admin_delete($id = null) {
		if (!$id) {
			$this->Session->setFlash('Invalid id for Semester Apartement');
			$this->redirect('/admin/semester_apartements/index');
		}
		if ($this->SemesterApartement->del($id)) {
			$this->Session->setFlash('The Semester Apartement deleted: id '.$id.'');
			$this->redirect('/admin/semester_apartements/index');
		}
	}

}
?>
